﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BXH.Movie.Model;
using BXH.Movie.Bll;
using CCWin;
using BXH.Movie.FrmUsers;

namespace BXH.Movie.Forms
{
    public partial class UCOrder : UserControl
    {
        private List<OrderInfoInput> _orderInfoInputs;
        private MovieInfoDto _movieInfo;
        private OrderInfoService orderInfoService = new OrderInfoService();
        private MovieInfoService movieService = new MovieInfoService();
        public UCOrder(List<OrderInfoInput> orderInfoInputs, MovieInfoDto movieInfo)
        {
            InitializeComponent();
            _orderInfoInputs = orderInfoInputs;
            _movieInfo = movieInfo;
        }
        /// <summary>
        /// 购买
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOrder_CheckedChanged(object sender, EventArgs e)
        {
            orderInfoService.Add(_orderInfoInputs);
            MessageBoxEx.Show("购买成功");

            var uCMovieMain = UControlCacheHelper.GetUControl<UCMovieMain>();
            uCMovieMain.Movies = movieService.GetMovieInfos().ToList();
            FrmMain._FrmMain.SetManageShow(uCMovieMain);
        }

        private void UCOrder_Load(object sender, EventArgs e)
        {

            var orderInfoDtos = new List<OrderInfoDto>();
            decimal tatolPrice = 0;
            foreach (var order in _orderInfoInputs)
            {
                tatolPrice += _movieInfo.TicketPrice;
                orderInfoDtos.Add(new OrderInfoDto
                {
                    MovieName = _movieInfo.Name,
                    Seat = $"{order.Seat.Split(',')[0] }排,{order.Seat.Split(',')[1]}座",
                    TicketPrice = _movieInfo.TicketPrice,
                    UserCode = Program.LoginUser.UserCode
                });
            }
            lbTotalPrice.Text = tatolPrice + "元";
            dataGridView1.DataSource = orderInfoDtos;


        }
    }
}
